#coding:utf-8
import json
import time
import logging
class Keyword:
    def __init__(self,path):
        logging.info('[+] 读取配置: '+path)
        self.m_cfg = self.loadCfg(path)
        self.m_dict = {}
        for key,res in self.m_cfg["path"].items():
            logging.info('[+] 加载资源: '+res)
            self.m_dict[key] = self.loadRes(res)

    # 读取配置文件
    def loadCfg(self,path):
        with open(path) as json_file:
            return json.load(json_file)

    # 读取资源文件
    def loadRes(self,path):
        list = []
        with open(path) as file:
            for line in file:
                list.append(line.strip())
        return list

    def cmp(self,word,list):
        for i, val in enumerate(list):
            if val.strip() == word.strip():
                return True
            if val.strip().upper() == word.strip().upper():
                return True
        return False

    def get(self,word):
        for key,list in self.m_dict.items():
            if self.cmp(word,list):
                return key
